//
//  PokemonList.swift
//  SwiftUI-Pokemaster
//
//  Created by gree on 2020/9/29.
//

import SwiftUI

struct PokemonList: View {
    
    @State var expandingIndex: Int?
    
    var body: some View {
        ScrollView {
            CustomSearchBar()
                .padding()
            ForEach(PokemonViewModel.all) {pokemon in
                PokemonInfoRow(expanded: self.expandingIndex == pokemon.id,
                               model: pokemon)
                    .onTapGesture(perform: {
                        if self.expandingIndex == pokemon.id {
                            self.expandingIndex = nil
                        } else {
                            self.expandingIndex = pokemon.id
                        }
                    })
            }
        }
//        .overlay(
//            VStack {
//                Spacer()
//                PokemonInfoPanel(model: .sample(id: 1))
//            }.edgesIgnoringSafeArea(.bottom)
//        )
    }
}

struct PokemonList_Previews: PreviewProvider {
    static var previews: some View {
        PokemonList()
    }
}
